extends "../cTDW/cTDW.gd"
func _info():
	pass

func _connect():
	._connect()

var norcnt:int = 0
var tlv = 0
var nlv = 0

var spw1 = 0.6
var spw2 = 1.08
var spw3 = 0.5

func _extInit():
	._extInit()
	#chaName = "圣剑客·Lv[0]"
	lv = 4
	attCoe.atkRan = 1
	attCoe.atk = 34 / 8.5 * 2 / 4
	attCoe.maxHp = 620 / 112.5 / 4
	addCdSkill("sjk",6)
	addSkillTxt("旋风斩：四次普攻[击中后]后触发旋风斩[对周围一格敌人连续造成5次伤害，每次60%物攻伤害")
	addSkillTxt("旋风斩·改：旋风斩每次伤害增加<12+技能等级*9>%[color=#666666][未解锁][/color]")
	addSkillTxt("圣剑：自身减伤增加<10+技能等级*2>%，物攻增加<15+技能等级*3>%，持续3秒[cd:6秒][color=#666666][未解锁][/color]")
	addSkillTxt("顺势劈：使用旋风斩后下一次普通攻击增加<50+技能等级*10>%伤害[color=#666666][未解锁][/color]")
	addSkillTxt("[color=red]Tips:杀人会获得经验，战斗结束后会计算经验并升级;升级获得的属性和解锁的技能及等级全局有效")
	nlv = 0
	lvup()
	if skill3unlock:
		skillunlock(3)
	if skill2unlock:
		skillunlock(2)
	if skill1unlock:
		skillunlock(1)

func _castCdSkill(id):
	._castCdSkill(id)
	if id == "sjk" && skill2unlock:
		addBuff(SJ.new(1,skill2lv))

func _onBattleStart():
	._onBattleStart()
	norcnt = 0
	if sys.test:
		lvup()
		if !skill3unlock:
			#print("unlock3")
			skillunlock(3)

func _onAtkChara(atkinfo):
	if atkinfo.atkType == Chara.AtkType.NORMAL && !atkinfo.isMiss && atkinfo.hitCha != self && atkinfo.atkCha == self:
		norcnt += 1
		if norcnt % 4 == 0:
			if skill1unlock:
				skill1up()
			cst("旋风斩","000000",position)
			var chas = getCellChas(cell,1)
			if chas.size():
				for j in range(5):
					for i in chas:
						if !i:continue
						hurtChara(i,att.atk*spw1,Chara.HurtType.PHY,Chara.AtkType.SKILL)
		if skill3unlock:
			#print("前：",atkinfo.hurtVal)
			if norcnt % 5 == 1 && norcnt != 1:
				skill3up()
				atkinfo.hurtVal *= (1 + spw3)
		#	print("后：",atkinfo.hurtVal)
	._onAtkChara(atkinfo)

func _onBattleEnd():
	._onBattleEnd()
	yield(reTimer(0.01),"timeout")
	lvup()
	upAtt()

func lvup():
	#killNum
#	print(killNum)
	#if chaName.find("Lv[") == -1:
	#	nlv = 0
	#else:
	#	nlv = int(chaName.right(chaName.find("[")).left(2))
#	print(nlv)
	if killNum >= 2:
		tlv = 1
	var e = 2
	var k = 3
	while(killNum >= e + k):
		tlv += 1
		e = e + k
		k += 1
	if sys.test:tlv = nlv + 1
	tlv = min(18,tlv)
	if tlv > nlv:
		upattadd(tlv,nlv)
		nlv = tlv
	chaName = "圣剑客·Lv[" + str(nlv) + "]"
		#print(chaName)

func upattadd(tlv,nlv):
	attAdd.atk += (tlv - nlv) * 7
	attAdd.maxHp += (tlv - nlv) * 69
	attAdd.def += (tlv - nlv) * 5
	attAdd.mgiDef += (tlv - nlv) * 5
	attAdd.spd += (tlv - nlv) * 0.025
	healCha(self,(tlv - nlv) * 20)

func skill1up():
	spw1 = 0.6 * (1 + skill1lv * 0.09 + 0.12)

func skill3up():
	spw3 = skill3lv * 0.1 + 0.5

class SJ:
	extends Buff
	func _init(lv,slv):
		attInit()
		life = 3
		id = "SJ"
		att.defR = (10.0 + slv * 2.0)/100.0
		att.atkL = (15.0 + slv * 3.0)/100.0